'use strict';
const Service = require('../core/base_service');

class SignInService extends Service {
  // 打卡
  async input (payload) {
    let res
    try {
      res = await this.ctx.model.SignIn.create(payload)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }

  // 获取信息
  async getSignIn (params) {
    let res
    try {
      res = await this.ctx.model.SignIn.find(params)
      console.log('getSignIn', res)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }
  // 获取信息
  async getSignInmohu (params) {
    let res
    try {
      if (params) {
        res = await this.ctx.model.SignIn.find({ name: { $regex: params.name } })
      } else {
        res = await this.ctx.model.SignIn.find()
      }
      console.log('getSignInmohu', res)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }

  // 修改
  async updateSignIn (payload) {
    let res
    try {
      res = await this.ctx.model.SignIn.findByIdAndUpdate(payload._id, payload)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }

  // 删除
  async deleteSignIn (payload) {
    let res
    try {
      res = await this.ctx.model.SignIn.findByIdAndRemove(payload._id)
      return this.success(res)
    } catch (error) {
      console.log(error)
    }
  }
}

module.exports = SignInService;
